<?php

/*

COMP 353F
Dr. B Desai
Final Project
Group #11

6330746 Nicholas CONSTANTINIDIS
9532862 Jacqueline FU
5484537 Claudio Javier LOPEZ FLORES
9218416 Que Tung NGUYEN

*/

  session_start();
?>

<!DOCTYPE html>
<html lang="en">
<head>
        <title>CoBAGSys - Home</title>
        <link type="text/css" rel="stylesheet" href="css/mystyle.css">
</head>
<body>
    <?php
      require 'menus.php';
    ?>
    <?php
    	// Returns the search results from the notifications table
    	function getMembers() 
	{
		$db = new Connect();

		$sql = "SELECT mi.mID, mi.mName, mp.mName as showName FROM MemberInfo mi JOIN MemberPrivacy mp on mi.mID = mp.mID";
		$result = $db->query($sql);
			
		if(!$result || mysql_num_rows($result) == 0)
		{
			return;
		}
		else
		{
			$rows = $db->to_array($result);
			return $rows;
		}
    	}
    ?>
    <div id="main">
    	<p class="title">Member List</p>
	<p class="normal\">Click on the member's number link to go to their page.</p>
	<form id="member" method="post">
	<?php
		$rows = getMembers();
	
		if (!isset($rows))
		{
			echo "No member found.";
		}
		else
		{
			echo "<table border=1>";
			echo "<tr>";
			echo "<th>ID</th>";
			echo "<th>Name</th>";
			echo "</tr>";

			$rowcount = count($rows);
			for ($i = 0; $i < $rowcount; $i++)
			{			
				echo "<tr>";
				echo '<td><a href="memberprofile.php?mid='.$rows[$i]['mID'].'"> '. $rows[$i]['mID'] .'</a></td>';
				echo '<td>'. (($rows[$i]['showName']) ? $rows[$i]['mName'] : 'Anonymous' ) .'</td>';
				echo "</tr>";
			}
		}
		echo "</table>";		
	?>
	</form>
    </div>
</body>
</html>